package com.controller.staticanaly;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.po.InformationInfo;
import com.po.NumberInfo;
import com.po.RoleInfo;
import com.po.UserDownloadInfo;
import com.service.infocenter.RoleService;
import com.service.information.InformationService;
import com.service.staticanaly.StatisticsService;


@Controller
@RequestMapping("/jsp/staticanaly")
public class MystaticController {
    @Resource(name="statisticsServiceImp")
    private StatisticsService statisticsService;
    @Resource(name="informationServiceImp")
    private InformationService informationService;
    @Resource(name="roleServiceImp")
    private RoleService roleService;
      
        @RequestMapping(value="/getUploadNumberview")
	public String getUploadNumberview(Model model, HttpServletRequest request, HttpServletResponse resp){
		List<RoleInfo> list=roleService.getRoleList();
		model.addAttribute("rolelist", list);
		return "staticanaly/uploadcount";
	}
        
	@RequestMapping(value="/getStaticanalyview")
	public String getStaticanalyview(Model model, HttpServletRequest request, HttpServletResponse resp){
		List<RoleInfo> list=roleService.getRoleList();
		model.addAttribute("rolelist", list);
		return "staticanaly/staticanaly";
	}	
	@ResponseBody
	@RequestMapping(value="/getInformationByBrowser")
	public Map<String, Object> getInformationByBrowser(int limit,int offset,String ku,int count,String starttime,String endtime){
		Map<String, Object> map = new HashMap<String, Object>();
		List<InformationInfo> list=statisticsService.getInformationListByBrowser(offset, limit, ku, count, starttime, endtime);
		int cc=statisticsService.getInformationCountByBrowser(offset, limit, ku, count, starttime, endtime);
		map.put("total", Math.min(cc, Math.abs(count)));
		map.put("rows", list);
		return map;
	}
	@ResponseBody
	@RequestMapping(value="/getInformationByDownload")
	public Map<String, Object> getInformationByDownload(int limit,int offset,String ku,int count,String starttime,String endtime){
		Map<String, Object> map = new HashMap<String, Object>();
		List<InformationInfo> list=statisticsService.getInformationListByDownload(offset, limit, ku, count, starttime, endtime);
		int cc=statisticsService.getInformationCountByBrowser(offset, limit, ku, count, starttime, endtime);
		map.put("total", Math.min(cc, Math.abs(count)));
		map.put("rows", list);
		return map;
	}
	@ResponseBody
	@RequestMapping(value="/getUserDownload")
	public Map<String, Object> getUserDownload(int limit,int offset,String ku,int count,String starttime,String endtime){
		Map<String, Object> map = new HashMap<String, Object>();
		List<UserDownloadInfo> list=statisticsService.getUserDownloadList(offset, limit, ku, count, starttime, endtime);
		int cc=statisticsService.getUserDownloadCount(offset, limit, ku, count, starttime, endtime);
		map.put("total", Math.min(cc, Math.abs(count)));
		map.put("rows", list);
		return map;
	}
	
	@ResponseBody
	@RequestMapping(value="/getUserNumber")
	public Map<String, Object> getUserNumber(int limit,int offset,String type,String starttime,String endtime){
		Map<String, Object> map = new HashMap<String, Object>();
		List<NumberInfo> list=statisticsService.getUserNumberList(offset, limit, type, starttime, endtime);
		int cc=statisticsService.getUserNumberCount(offset, limit, type, starttime, endtime);
		map.put("total", cc);
		map.put("rows", list);
		return map;
	}
	@ResponseBody
	@RequestMapping(value="/getInfoNumber")
	public Map<String, Object> getInfoNumber(int limit,int offset,String ku,String starttime,String endtime,String type){
		Map<String, Object> map = new HashMap<String, Object>();
		List<NumberInfo> list=statisticsService.getInfoNumberList(offset, limit, ku, starttime, endtime,type);
		int cc=statisticsService.getInfoNumberCount(offset, limit, ku, starttime, endtime,type);
		map.put("total", cc);
		map.put("rows", list);
		return map;
	}
	@ResponseBody
	@RequestMapping(value="/getAccessNumber")
	public Map<String, Object> getAccessNumber(int limit,int offset,String way,String starttime,String endtime){
		Map<String, Object> map = new HashMap<String, Object>();
		List<NumberInfo> list=statisticsService.getAccessNumberList(offset, limit, way, starttime, endtime);
		int cc=statisticsService.getAccessNumberCount(offset, limit, way, starttime, endtime);
		map.put("total", cc);
		map.put("rows", list);
		return map;
	}
	@ResponseBody
	@RequestMapping(value="/getInformationByUpload")
	public Map<String, Object> getInformationByUpload(int limit,int offset,String ku,String userid,String way,String starttime,String endtime){
		Map<String, Object> map = new HashMap<String, Object>();
		List<InformationInfo> list=statisticsService.getInformationListByUpload(offset, limit, ku, userid, way,starttime, endtime);
		int cc=statisticsService.getInformationCountByUpload(offset, limit, ku, userid,way, starttime, endtime);
		map.put("total", cc);
		map.put("rows", list);
		return map;
	}
}
